package com.execl.service.impl;

import com.execl.service.ExeclServices;
import com.github.pagehelper.PageInfo;
import com.execl.dao.ExeclDao;
import com.execl.entity.Execl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ExeclServiceImpl implements ExeclServices
{
    @Autowired
    ExeclDao execlDao;

    @Override
    public List<Execl> findUser(String name, PageInfo pageInfo) {
        // 分页查询返回的数据，前端需要传 pageNum 与 pageSize
        Map<String, Object> execlMap = new HashMap<>();
        if (null == pageInfo) {
            execlMap.put("limitStart", 0);
            execlMap.put("limitEnd", 20);
        } else {
            if (pageInfo.getPageNum() < 1) pageInfo.setPageNum(1);
            if (pageInfo.getPageSize() < 1) pageInfo.setPageSize(20);
            execlMap.put("limitStart", (pageInfo.getPageNum() - 1) * pageInfo.getPageSize());
            execlMap.put("limitEnd", pageInfo.getPageNum() * pageInfo.getPageSize());
        }

        List<Execl> list = execlDao.findExeclByName(name);
        if (null == list) list = new ArrayList<>();
        return list;
    }
}
